<template>
  <el-dialog
    title="修改学生就业信息"
    :visible.sync="dialogVisible"
    width="500px">
    <el-form label-width="100px" :model="formData" ref="form" :rules="rules">
      <el-form-item label="公司名称" prop="companyName">
        <el-input v-model="formData.companyName" class="commonStyle" size="medium"></el-input>
      </el-form-item>
      <el-form-item label="岗位" prop="position">
        <el-input v-model="formData.position" class="commonStyle" size="medium"></el-input>
      </el-form-item>
      <el-form-item label="入职日期" prop="signedDate">
        <el-date-picker
          v-model="formData.signedDate"
          value-format="yyyy-MM-dd"
          type="date"
          size="medium"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="danger" size="medium" @click="cancel">取消</el-button>
      <el-button type="primary" size="medium" @click="update">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { updateStuJob } from '@/api/stuJobManage'

export default {
  name: "index",
  data() {
    return {
      // 控制弹窗
      dialogVisible: false,
      // 表单中的信息
      formData: {

      },
      rules: {
        companyName: [
          { required: true, message: '请输入公司名称', trigger: 'blur' }
        ],
        position: [
          { required: true, message: '请输入岗位', trigger: 'blur' }
        ],
        signedDate: [
          { required: true, message: '请选择入职日期', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 打开弹框
    openDialog(val) {
      this.formData = {...val}
      this.dialogVisible = true
    },
    // 取消
    cancel() {
      this.initData()
      this.dialogVisible = false
    },
    // 初始化数据
    initData() {
      this.formData = {

      }
    },
    // 更新或新增
    async update() {
      this.$refs.form.validate(async (valid) => {
        if(!valid) {
          return false
        } else {
          const res = await updateStuJob(this.formData)
          if (res.success == true) {
            this.$message.success(res.data)
            this.$emit('reloadData')
            this.dialogVisible = false
          } else {
            this.$message.error(res.errorMsg)
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="sass">
.commonStyle
  width: 200px
</style>
